<template>
	<view>
		<view class="box_bg"
			:style="'background: url('+ z_imgPath + 'shouye/indexBg.png'+ ') repeat-y 0 0 / 100% auto;'">

		</view>
		<!-- #ifdef MP-WEIXIN -->
		<view v-if="isCanUse">
			<view>
				<view class='header'>
					<image :src="z_imgPath + 'shouye/logo.png'"></image>
				</view>
				<view class=' content'>
					<view>申请获取以下权限</view>
					<text>获得你的公开信息(昵称，头像、地区等)</text>
				</view>
				<button class='bottom' type='primary' withCredentials="true" lang="zh_CN" v-if="is_xy"
					@tap="getUserProfile">授权登录</button>
				<button class='bottom' type='primary' withCredentials="true" lang="zh_CN" v-else
					@click="toast">授权登录</button>

			</view>
		</view>
		<view style="font-size: 24rpx;" class="desc" @click="is_xy = !is_xy">
			<image :src="z_imgPath + 'detail/yuan'+ (is_xy?'_sel':'') +'.png'"></image>
			我已阅读并同意
			<text style="color: #B07CDD;" @click="gotoPage('/pages/guize/guize?type=2')">《用户服务协议条款》</text>
		</view>
		<!-- #endif -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				z_imgPath: 'https://qt.yhemall.com/',
				SessionKey: '',
				OpenId: '',
				nickName: null,
				avatarUrl: null,
				isCanUse: uni.getStorageSync('isCanUse') || true, //默认为true
				code: '',
				is_xy: false,
			};
		},
		onLoad() { //默认加载
			// this.login();
		},
		methods: {
			toast() {
				uni.showToast({
					title: '请阅读并同意下方协议！',
					duration: 2000,
					icon: 'none'
				})
			},
			//第一授权获取用户信息===》按钮触发
			getUserProfile(e) {
				var that = this;
				uni.getUserProfile({
					desc: '用于向用户发送商品', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					lang: 'zh_CN',
					success: (res) => {
						uni.login({
							provider: 'weixin',
							success: function(loginRes) {
								that.req({
									url: 'login',
									data: {
										code: loginRes.code,
										nickname: res.userInfo.nickName,
										headimg: res.userInfo.avatarUrl,
										pid: uni.getStorageSync('pid'),
										from: uni.getStorageSync('from')
									},
									success: function(res) {
										if (res.status == 1) {
											uni.setStorageSync('token', res.data);
											var lgurl = uni.getStorageSync(
												'lgurl'); //获取页面路径
											var lgdata = uni.getStorageSync(
												'lgurldata') //获取页面参数
											if (lgurl) {
												lgdata = JSON.parse(lgdata)
												// 拼接参数
												let param = ''
												for (let key in lgdata) {
													param += '&' + key + '=' + lgdata[
														key]
												}
												param = '/' + lgurl + param.replace(
													'&', '?')
												uni.setStorageSync('lgurl', '');
												uni.setStorageSync('lgurldata', '')
												console.log(param)
												setTimeout(() => {
													uni.reLaunch({
														url: param
													})

												}, 1000)
											} else {
												uni.reLaunch({
													url: 'index'
												})
											}

										}
									}
								})
							}
						});
					}
				})
			},


		}

	}
</script>

<style lang="scss">
	.desc {
		margin: 0 50rpx;
		display: flex;
		align-items: center;
		color: #fff;

		image {
			width: 40rpx;
			height: 40rpx;
			margin-right: 10rpx;
		}
	}

	.header {
		margin: 90rpx 0 90rpx 50rpx;
		border-bottom: 1px solid #ccc;
		text-align: center;
		width: 650rpx;
		height: 300rpx;
		line-height: 450rpx;
	}

	.header image {
		width: 200rpx;
		height: 200rpx;
	}

	.content {
		margin-left: 50rpx;
		margin-bottom: 90rpx;
		color: #fff;
	}

	.content text {
		display: block;
		margin-top: 40rpx;
	}

	.bottom {
		border-radius: 80rpx;
		margin: 70rpx 50rpx 20rpx;
		font-size: 35rpx;
	}
</style>